package com.asp.alumnisystem.presenter;

import com.asp.alumnisystem.app.App;
import com.asp.alumnisystem.base.BaseBean;
import com.asp.alumnisystem.base.BasePresenter;
import com.asp.alumnisystem.base.IView;
import com.asp.alumnisystem.net.RetrofitManager;
import com.asp.alumnisystem.utils.ToastUtil;

import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;

/**
 * 查找好友关系，添加好友, 删除好友 的Presenter
 */
public class OptFriendPresenter extends BasePresenter<Long, Boolean> {

    public OptFriendPresenter(IView view) {
        super(view);
    }

    /**
     * 查找好友关系
     */
    @Override
    protected Boolean request(Long userId) throws Exception {
        return false;
    }

    @Override
    protected Observable<BaseBean<Boolean>> requestNet(Long s) {
        return RetrofitManager.getApi().isMyFriend(App.getApp().getUserId(), s);
    }

    /**
     * 添加好友
     */
    public void addFriend(Long userId){
        ToastUtil.showShortToast("好友添加成功！");
        RetrofitManager.getApi().addFriend(App.getApp().getUserId(), userId)
                .subscribeOn(Schedulers.io())
                .subscribe();
    }

    /**
     * 添加好友
     */
    public void delFriend(Long userId){
        RetrofitManager.getApi().delFriend(App.getApp().getUserId(), userId)
                .subscribeOn(Schedulers.io())
                .subscribe();
    }

}
